USE [master]
GO

IF EXISTS (SELECT * FROM [sys].[databases] WHERE [name] = N'HierarchyIdDemo')
	BEGIN
		ALTER DATABASE HierarchyIdDemo SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
		DROP DATABASE HierarchyIdDemo;
	END
GO

CREATE DATABASE HierarchyIdDemo
GO

USE HierarchyIdDemo
GO

IF EXISTS (SELECT * FROM [sys].[schemas] WHERE [name] = N'SelfJoin')
	BEGIN
		DROP SCHEMA SelfJoin;
	END
GO

CREATE SCHEMA SelfJoin
GO

IF EXISTS (SELECT * FROM [sys].[schemas] WHERE [name] = N'HierarchyId')
	BEGIN
		DROP SCHEMA HierarchyId;
	END
GO

CREATE SCHEMA HierarchyId
GO